package com.acwing.partition44;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/27 19:29
 */
public class AC4380合并石子_双指针 {

    private static final int N = 100010;
    private static int[] a = new int[N], b = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        ss = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) a[i] = Integer.parseInt(ss[i]);
        ss = reader.readLine().split(" ");
        for (int i = 0; i < m; i++) b[i] = Integer.parseInt(ss[i]);
        int ans = 0, s1 = a[0], s2 = b[0];
        for (int i = 1, j = 1; i <= n && j <= m; ) {
            if (s1 > s2) s2 += b[j++];
            else if (s1 < s2) s1 += a[i++];
            else {
                ans++;
                if (i < n && j < m) {
                    s1 = a[i];
                    s2 = b[j];
                }
                i++;
                j++;
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
